package com.comac.tasks.manager.app.dto;

import com.alibaba.cola.dto.Response;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import java.util.List;

/**
 * @author cyg
 */
@Data
public class PageResponse<T> extends Response {
    private Long pageSize;
    private Long pageNum;
    private Long totalCount;
    private List<T> data;

    public static <T> PageResponse<T> successPage(Page<T> pageData) {
        PageResponse<T> pageResponse = new PageResponse<>();
        pageResponse.setSuccess(true);
        pageResponse.setData(pageData.getRecords());
        pageResponse.setPageSize(pageData.getSize());
        pageResponse.setPageNum(pageData.getCurrent());
        pageResponse.setTotalCount(pageData.getTotal());
        return pageResponse;
    }

    public static PageResponse buildFailure(String errCode, String errMessage) {
        PageResponse response = new PageResponse();
        response.setSuccess(false);
        response.setErrCode(errCode);
        response.setErrMessage(errMessage);
        return response;
    }

    public static PageResponse buildSuccess() {
        PageResponse response = new PageResponse();
        response.setSuccess(true);
        return response;
    }

}

